//
//  HOQuestionEntity.m
//  微度报修
//
//  Created by foguo-mac-1 on 08/05/2017.
//  Copyright © 2017 WeiDu. All rights reserved.
//

#import "HOQuestionEntity.h"
#import "HOConstants.h"

@implementation HOReplyEntity

- (void)dealloc
{
	self.replyContent = nil;
	
	[super dealloc];
}
@end

@implementation HOQuestionEntity
- (instancetype)init
{
	self = [super init];
	if(self)
	{
		if(self.replyList == nil)
		{
			self.replyList = [[[NSMutableArray alloc] init] autorelease];
		}
	}
	return self;
}
/*
 @interface HOReplyEntity : HOBaseEntity
 @property(nonatomic, assign)BOOL isAskerReply;
 @property(nonatomic, retain)NSString *replyContent;
 @property(nonatomic, assign)double replyTime;
 @end
 
 @interface HOQuestionEntity : HOBaseEntity
 @property(nonatomic, retain)NSString *questionTitle;
 @property(nonatomic, assign)int questionId;
 @property(nonatomic, assign)double createTime;
 @property(nonatomic, retain)NSArray *replyList;
 @end

 */
- (void)parseDic:(NSDictionary *)dic
{
	self.questionTitle = [dic objectForKey:kHO_FIELD_Title];
	self.questionId = [[dic objectForKey:kHO_FIELD_QuestionId] intValue];
	self.createTime = [[dic objectForKey:kHO_FIELD_CreateTime] doubleValue];
	
	HOReplyEntity *entity = [[[HOReplyEntity alloc] init] autorelease];
	entity.isAskerReply = YES;
	entity.replyContent = self.questionTitle;
	entity.replyTime = self.createTime;
	[self.replyList addObject:entity];
}

- (void)clearReplyList
{
	HOReplyEntity *entity = [self.replyList.firstObject retain];
	[self.replyList removeAllObjects];
	[self.replyList addObject:entity];
	[entity release];
}

- (void)parseDetailDic:(NSDictionary *)dic
{
	[self clearReplyList];
	NSArray *replyList = [dic objectForKey:kHO_FIELD_ReplyList];
	if(replyList)
	{
		[self parseReplyList:replyList];
	}
}

- (void)parseReplyList:(NSArray *)array
{
	for(int i = 0; i < [array count]; i ++)
	{
		NSDictionary *dic = [array objectAtIndex:i];
		HOReplyEntity *entity = [[[HOReplyEntity alloc] init] autorelease];
		entity.isAskerReply = [[dic objectForKey:kHO_FIELD_IsAskerReply] boolValue];
		entity.replyContent = [dic objectForKey:kHO_FIELD_ReplyContent];
		entity.replyTime = [[dic objectForKey:kHO_FIELD_ReplyTime] doubleValue];
		
		[self.replyList addObject:entity];
	}
}

- (void)dealloc
{
	self.questionTitle = nil;
	[self.replyList removeAllObjects];
	self.replyList = nil;
	[super dealloc];
}


@end
